﻿using System;
using System.Windows.Forms;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;

namespace TSPquestEDITOR
{
    public partial class basic_info : Form
    {
        delegate void update_text_delegate();

        public void update_ui_txt(int var, string text)
        {
            if (var == 0) //Status updates only
            {
                status.Text = text;
            }
            if (var == 1)
            {
                this.BeginInvoke(new update_text_delegate(update_text));
            }
            if (var == 2)
            {
                progBar1.Value = 100;
                status.Text = "COMPLETE";
            }
        }

        private void update_text()
        {
            quest_name_box.Text = quest_name_val;
            quest_id.Text = quest_id_val.ToString();
            toolTip1.SetToolTip(quest_name_box, quest_name_val + " : " + quest_name_id_val.ToString());
            quest_name_box.Text = quest_name_val;
            quest_type.Text = quest_type_val;
            //If the Class Limit variables have been assigned
            //e.g. not = 0
            if (limit_deva_val != 0 || limit_asura_val != 0 || limit_gaia_val != 0)
            {
                if (limit_deva_val == 1 & limit_asura_val == 1 & limit_gaia_val == 1)
                {
                    //All
                    //Lets inform the UI
                    quest_class_req_box.Text = "ALL";
                }
                if (limit_deva_val == 1 & limit_asura_val == 0 & limit_gaia_val == 0)
                {
                    //Deva
                    //Lets inform the UI
                    quest_class_req_box.Text = "DEVA";
                }
                if (limit_deva_val == 0 & limit_asura_val == 1 & limit_gaia_val == 0)
                {
                    //Asura
                    //Lets inform the UI
                    quest_class_req_box.Text = "ASURA";
                }
                if (limit_deva_val == 0 & limit_asura_val == 0 & limit_gaia_val == 1)
                {
                    //Gaia
                    //Lets inform the UI
                    quest_class_req_box.Text = "GAIA";
                }
            }
            exp_box.Text = quest_exp_val.ToString();
            jp_box.Text = quest_jp_val.ToString();
            gold_box.Text = quest_gold_val.ToString();
            holicpoint_box.Text = quest_holicpoint_val.ToString();
            level_req.Text = quest_level_req_val.ToString();
            quest_max_lv_box.Text = quest_limit_max_lv_val.ToString();
            quest_min_jlv.Text = quest_limit_job_lv_val.ToString();
            //Translate time_type
            if (quest_time_type_val != 0)
            {
                quest_time_type.Text = "TIMED";
            }
            else
            {
                quest_time_type.Text = "UNTIMED";
            }
            quest_time_limit.Text = quest_time_limit_val.ToString();
            //To avoid bugs we reset NPC Box.ReadOnly = false;
            start_npc_id.ReadOnly = false;
            start_npc_giver_title.ReadOnly = false;
            start_npc_name.ReadOnly = false;
            start_npc_x.ReadOnly = false;
            start_npc_y.ReadOnly = false;
            start_npc_lua.ReadOnly = false;
            start_npc_2_id.ReadOnly = false;
            start_npc_2_title.ReadOnly = false;
            start_npc_2_name.ReadOnly = false;
            start_npc_2_x.ReadOnly = false;
            start_npc_2_y.ReadOnly = false;
            start_npc_2_lua.ReadOnly = false;
            start_npc_3_id.ReadOnly = false;
            start_npc_3_title.ReadOnly = false;
            start_npc_3_name.ReadOnly = false;
            start_npc_3_x.ReadOnly = false;
            start_npc_3_y.ReadOnly = false;
            start_npc_3_lua.ReadOnly = false;
            end_npc_id.ReadOnly = false;
            end_npc_giver_title.ReadOnly = false;
            end_npc_name.ReadOnly = false;
            end_npc_x.ReadOnly = false;
            end_npc_y.ReadOnly = false;
            end_npc_lua_box.ReadOnly = false;          
            //Make sure NPC ID val isn't 0 before we set Start NPC Info
            if (quest_start_npc_id_val != 0)
            {
                start_npc_id.Text = quest_start_npc_id_val.ToString();
                start_npc_giver_title.Text = quest_start_npc_title_val.ToString();
                start_npc_name.Text = quest_start_npc_name_val.ToString();
                start_npc_x.Text = quest_start_npc_x_val.ToString();
                start_npc_y.Text = quest_start_npc_y_val.ToString();
                start_npc_lua.Text = quest_start_npc_lua_val.ToString();
            }
            else
            {
                start_npc_id.Text = "".ToString();
                start_npc_id.ReadOnly = true;
                start_npc_giver_title.Text = "".ToString();
                start_npc_giver_title.ReadOnly = true;
                start_npc_name.Text = "".ToString();
                start_npc_name.ReadOnly = true;
                start_npc_x.Text = "".ToString();
                start_npc_x.ReadOnly = true;
                start_npc_y.Text = "".ToString();
                start_npc_y.ReadOnly = true;
                start_npc_lua.Text = "".ToString();
                start_npc_lua.ReadOnly = true;
            }
            //Make sure NPC 2 ID val isn't 0 before we set NPC 2 info
            if (quest_start_npc_2_id_val != 0)
            {
                start_npc_2_id.Text = quest_start_npc_2_id_val.ToString();
                start_npc_2_title.Text = quest_start_npc_2_title_val;
                start_npc_2_name.Text = quest_start_npc_2_name_val;
                start_npc_2_x.Text = quest_start_npc_2_x_val.ToString();
                start_npc_2_y.Text = quest_start_npc_2_y_val.ToString();
                start_npc_2_lua.Text = quest_start_npc_2_lua_val;
            }
            else
            {
                start_npc_2_id.Text = "".ToString();
                start_npc_2_id.ReadOnly = true;
                start_npc_2_title.Text = "";
                start_npc_2_title.ReadOnly = true;
                start_npc_2_name.Text = "";
                start_npc_2_name.ReadOnly = true;
                start_npc_2_x.Text = "".ToString();
                start_npc_2_x.ReadOnly = true;
                start_npc_2_y.Text = "".ToString();
                start_npc_2_y.ReadOnly = true;
                start_npc_2_lua.Text = "";
                start_npc_2_lua.ReadOnly = true;

            }
            //Make sure NPC 3 ID Val isn't 0 before we set NPC 3 info
            if (quest_start_npc_3_id_val != 0)
            {
                start_npc_3_id.Text = quest_start_npc_3_id_val.ToString();
                start_npc_3_title.Text = quest_start_npc_3_title_val;
                start_npc_3_name.Text = quest_start_npc_3_name_val;
                start_npc_3_x.Text = quest_start_npc_3_x_val.ToString();
                start_npc_3_y.Text = quest_start_npc_3_y_val.ToString();
                start_npc_3_lua.Text = quest_start_npc_3_lua_val;
            }
            else
            {
                start_npc_3_id.Text = "".ToString();
                start_npc_3_id.ReadOnly = true;
                start_npc_3_title.Text = "";
                start_npc_3_title.ReadOnly = true;
                start_npc_3_name.Text = "";
                start_npc_3_name.ReadOnly = true;
                start_npc_3_x.Text = "".ToString();
                start_npc_3_x.ReadOnly = true;
                start_npc_3_y.Text = "".ToString();
                start_npc_3_y.ReadOnly = true;
                start_npc_3_lua.Text = "";
                start_npc_3_lua.ReadOnly = true;
            }
            //Make sure End NPC ID isn't 0 before we set END NPC Info
            if (quest_end_npc_id_val != 0)
            {
                end_npc_id.Text = quest_end_npc_id_val.ToString();
                end_npc_giver_title.Text = quest_end_npc_title_val.ToString();
                end_npc_name.Text = quest_end_npc_name_val;
                end_npc_x.Text = quest_end_npc_x_val.ToString();
                end_npc_y.Text = quest_end_npc_y_val.ToString();
                end_npc_lua_box.Text = quest_end_npc_lua_val;
            }
            else
            {
                end_npc_id.Text = "".ToString();
                end_npc_id.ReadOnly = true;
                end_npc_giver_title.Text = "".ToString();
                end_npc_giver_title.ReadOnly = true;
                end_npc_name.Text = "".ToString();
                end_npc_name.ReadOnly = true;
                end_npc_x.Text = "".ToString();
                end_npc_x.ReadOnly = true;
                end_npc_y.Text = "".ToString();
                end_npc_y.ReadOnly = true;
                end_npc_lua_box.Text = "".ToString();
                end_npc_lua_box.ReadOnly = true;
            }

            //Check if the Objective ID is 0 if so we don't wanna display it
            //or it's related info
            if (quest_obj_1_id_val != 0)
            {
                if (quest_type_internal_reference == "MONSTER")
                {
                    apply_list_obj_monster();
                }
                else if (quest_type_internal_reference == "ITEM")
                {
                    apply_list_obj_item();
                }
                else if (quest_type_internal_reference == "SKILL")
                {
                    apply_list_obj_skill();
                }    
                //We have a good Quest Objective ID, let's go ahead and 
                //display the information.
                quest_obj_1_id_box.Text = quest_obj_1_id_val.ToString();
                quest_obj_1_amount_box.Text = quest_obj_1_amount_val.ToString();
                quest_obj_1_name_box.Text = quest_obj_1_name_val;
            }
            else
            {
                quest_obj_1_id_box.Text = "";
                quest_obj_1_name_box.Text = "";
                quest_obj_1_amount_box.Text = "";
            }
            //Check if the Objective ID 2 is - if so we don't wanna display it
            //or it's related info
            if (quest_obj_2_id_val == 0)
            {
                quest_obj_2_id_box.Text = "";
                quest_obj_2_name_box.Text = "";
                quest_obj_2_amount_box.Text = "";
            }
            else
            {
                //We have a good Quest Objective ID 2, lets go ahead
                //and display the information
                quest_obj_2_id_box.Text = quest_obj_2_id_val.ToString();
                quest_obj_2_name_box.Text = quest_obj_2_name_val;
                quest_obj_2_amount_box.Text = quest_obj_2_amount_val.ToString();
            }
            //Check if the Objective ID 3 is 0 if so we don't wanna display it
            //or it's related info
            if (quest_obj_3_id_val == 0)
            {
                quest_obj_3_id_box.Text = "";
                quest_obj_3_name_box.Text = "";
                quest_obj_3_amount_box.Text = "";
            }
            else
            {
                quest_obj_3_id_box.Text = quest_obj_3_id_val.ToString();
                quest_obj_3_name_box.Text = quest_obj_3_name_val;
                quest_obj_3_amount_box.Text = quest_obj_3_amount_val.ToString();
            }
            //Check if Default Reward ID is 0 if so we don't wanna display it
            //or it's related info
            if (quest_def_rew_id_val == 0)
            {
                quest_def_rew_id_box.Text = "";
                quest_def_rew_name_box.Text = "";
                quest_def_rew_amount_box.Text = "";
            }
            else
            {
                //Update Quest Def Rew GrpBox with relevant info
                quest_def_rew_id_box.Text = quest_def_rew_id_val.ToString();
                quest_def_rew_name_box.Text = quest_def_rew_name_val;
                quest_def_rew_amount_box.Text = quest_def_rew_amount_val.ToString();
            }

            //Display Descriptions
            start_desc_id.Text = quest_start_desc_id_val.ToString();
            start_desc.Text = quest_start_desc_val.ToString();
            //Check if Progress Description ID = 0
            if (quest_prog_desc_id_val == 0)
            {
                prog_desc_id.Text = "";
                prog_desc.Text = "";
            }
            else
            {
                prog_desc_id.Text = quest_prog_desc_id_val.ToString();
                prog_desc.Text = quest_prog_desc_val.ToString();
            }
            end_desc_id.Text = quest_end_desc_id_val.ToString();
            end_desc.Text = quest_end_desc_val;

            //Update ProgBar1
            progBar1.Value = 100;

            //We should unset Multi_quest_search_return_id
            multi_quest_search_return_id = "";

            //Out task is finished, let's update the ui status
            status.Text = "COMPLETE";
        }
    }   
}